package com.abberbex;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;

public class Portal {
	
	private Image portal;
	
	public boolean isRedOpen;
	public boolean isBlueOpen;

	private float rX;
	private float rY;
	
	private float bX;
	private float bY;
	
	private Rectangle rBounds;
	private Rectangle bBounds;
	
	public boolean bL, bU, bD, bR = false;
	public boolean rL, rU, rD, rR = false;
	
	public boolean blueVert;
	public boolean redVert;

	
	private void init() throws SlickException{
		
		portal = new Image("terrain/portal.png").getScaledCopy(32, 64);
	}
	
	public Portal() throws SlickException
	{
		init();
	}
	
	public float getRX() {
		return rX;
	}

	public float getRY() {
		return rY;
	}

	public float getBX() {
		return bX;
	}

	public float getBY() {
		return bY;
	}
	
	public void createRed(PortableSurface ps){
		redVert=false;
		rX=ps.getX()+16;
		if(rU){
		rY=ps.getY()-32;
		}
		else
		{
			rY=ps.getY();
		}
		rBounds = new Rectangle(rX-12, rY+24, portal.getHeight(),portal.getWidth()/2);
		isRedOpen=true;
	}
	
	public void createBlue(PortableSurface ps){
		blueVert=false;
		bX=ps.getX()+16;
		if(bU)
		{
		bY=ps.getY()-32;
		}
		else
		{
			bY=ps.getY();
		}
		bBounds = new Rectangle(bX-12, bY+24, portal.getHeight(),portal.getWidth()/2);
		isBlueOpen=true;
	}
	
	public void createRed(PortableWall pw){
		redVert = true; 
		rY=pw.getY();
		if(rL){
		rX=pw.getX()-16;
		}
		else
		{
			rX=pw.getX()+16;
		}
		rBounds = new Rectangle(rX+10, rY,portal.getWidth()/2,portal.getHeight());
		isRedOpen=true;
	}
	
	public void createBlue(PortableWall pw){
		blueVert=true;
		bY=pw.getY();
		if(bL){
		bX=pw.getX()-16;
		}
		else
		{
			bX=pw.getX()+16;
		}
		bBounds =  new Rectangle(bX+10, bY,portal.getWidth()/2,portal.getHeight());
		isBlueOpen=true;
	}
	
	public Rectangle getrBounds() {
		return rBounds;
	}

	public Rectangle getbBounds() {
		return bBounds;
	}

	public void draw(Graphics g)
	{
		
		if(isBlueOpen){
			if(!blueVert){
				portal.setRotation(90);
			}
			portal.draw(bX+portal.getWidth()/12, bY, portal.getWidth(),portal.getHeight(),Color.blue);
			portal.setRotation(0);
		}
		if(isRedOpen){
			if(!redVert)
			{
				portal.setRotation(90);
			}
			portal.draw(rX+portal.getWidth()/12, rY, portal.getWidth(),portal
					.getHeight(), Color.red);
			portal.setRotation(0);
		}
	}
	
	
}
